import { getAdminInfoApi } from "@/api/admin";
import { getWorkplacesApi } from "@/api/workplace";
import { setAdminInfo } from "@/store/slices/admin";
import { setWorkplace } from "@/store/slices/workplace";
import { useDispatch } from "react-redux"




const useSlicesData = () => {

    const dispatch = useDispatch();

    //获取当前登录用户信息
    const getAdminInfoHook = () => {
        getAdminInfoApi().then(res => {
            if (res.code == 200) {
                // dispatch调用状态机的公共方法，保存到到状态机
                dispatch(setAdminInfo(res.data));
            }
        })
    }

    //获取工作地点
    const getWorkplaceHook = () => {
        getWorkplacesApi().then(res => {
            if (res.code == 200) {
                // dispatch调用状态机的公共方法，保存到到状态机
                dispatch(setWorkplace(res.data));
            }
        })
    }
    return {
        getAdminInfoHook, getWorkplaceHook
    }
}


export default useSlicesData